﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

/// <summary>
///Picture 的摘要说明
/// </summary>
public class Picture
{
    private int pictureId;

    public int PictureId
    {
        get { return pictureId; }
        set { pictureId = value; }
    }

    private DateTime uploadDate;

    [JsonProperty(ItemConverterType = typeof(JavaScriptDateTimeConverter))]
    public DateTime UploadDate
    {
        get { return uploadDate; }
        set { uploadDate = value; }
    }

    private string category;

    public string Category
    {
        get { return category; }
        set { category = value; }
    }

    private string imagename;

    public string ImageName
    {
        get { return imagename; }
        set { imagename = value; }
    }

    public string smallImageName
    {
        get { return "small"+imagename; }
    }
 
	public Picture()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public static Picture ConvertToPicture(DataRow dr)
    {
        if(dr==null)
            return null;
        Picture picture = new Picture();
        if (dr["PictureId"] != null)
            picture.PictureId = Convert.ToInt32(dr["PictureId"]);
        if (dr["UploadDate"] != null)
            picture.UploadDate = Convert.ToDateTime(dr["UploadDate"].ToString());
        if (dr["Category"] != null)
            picture.Category = dr["Category"].ToString();
        if (dr["ImageName"] != null)
            picture.ImageName = dr["ImageName"].ToString();
        return picture;

    }

    public static IList<Picture> ConvertToPictureList(DataTable dt)
    {
        List<Picture> picturelist = new List<Picture>();
        foreach (DataRow dr in dt.Rows)
        {
            Picture picture = ConvertToPicture(dr);
            if (picture != null)
                picturelist.Add(picture);
        }
        return picturelist;
    }
}
